package jester;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import data.DataBig;
import file.ParseJester;

public class Jester_MakeDataset {

	/**
	 * @param args
	 */
	
	public static void main(String[] args) throws IOException {
		
		ParseJester pj = new ParseJester();
		List<DataBig> data = pj.getList();

		BufferedWriter train1 = new BufferedWriter(new FileWriter("D:\\Jester Dataset\\train1"));
		BufferedWriter test1 = new BufferedWriter(new FileWriter("D:\\Jester Dataset\\test1"));

		BufferedWriter train2 = new BufferedWriter(new FileWriter("D:\\Jester Dataset\\train2"));
		BufferedWriter test2 = new BufferedWriter(new FileWriter("D:\\Jester Dataset\\test2"));

		BufferedWriter train3= new BufferedWriter(new FileWriter("D:\\Jester Dataset\\train3"));
		BufferedWriter test3 = new BufferedWriter(new FileWriter("D:\\Jester Dataset\\test3"));

		BufferedWriter train4 = new BufferedWriter(new FileWriter("D:\\Jester Dataset\\train4"));
		BufferedWriter test4 = new BufferedWriter(new FileWriter("D:\\Jester Dataset\\test4"));

		BufferedWriter train5 = new BufferedWriter(new FileWriter("D:\\Jester Dataset\\train5"));
		BufferedWriter test5 = new BufferedWriter(new FileWriter("D:\\Jester Dataset\\test5"));
		
		int i=0;
		
		for(DataBig datum : data){
			int uid = datum.uid;
			int iid = datum.iid;
			double rat = datum.rat;

			switch(i){
				case 0:
					test1.write(uid+","+iid+","+rat+"\n");
					train2.write(uid+","+iid+","+rat+"\n");
					train3.write(uid+","+iid+","+rat+"\n");
					train4.write(uid+","+iid+","+rat+"\n");
					train5.write(uid+","+iid+","+rat+"\n");
					i=1;
					break;
				case 1:
					test2.write(uid+","+iid+","+rat+"\n");
					train1.write(uid+","+iid+","+rat+"\n");
					train3.write(uid+","+iid+","+rat+"\n");
					train4.write(uid+","+iid+","+rat+"\n");
					train5.write(uid+","+iid+","+rat+"\n");
					i=2;
					break;
				case 2:
					test3.write(uid+","+iid+","+rat+"\n");
					train2.write(uid+","+iid+","+rat+"\n");
					train1.write(uid+","+iid+","+rat+"\n");
					train4.write(uid+","+iid+","+rat+"\n");
					train5.write(uid+","+iid+","+rat+"\n");
					i=3;
					break;
				case 3:
					test4.write(uid+","+iid+","+rat+"\n");
					train2.write(uid+","+iid+","+rat+"\n");
					train3.write(uid+","+iid+","+rat+"\n");
					train1.write(uid+","+iid+","+rat+"\n");
					train5.write(uid+","+iid+","+rat+"\n");
					i=4;
					break;
				case 4:
					test5.write(uid+","+iid+","+rat+"\n");
					train2.write(uid+","+iid+","+rat+"\n");
					train3.write(uid+","+iid+","+rat+"\n");
					train4.write(uid+","+iid+","+rat+"\n");
					train1.write(uid+","+iid+","+rat+"\n");
					i=0;
					break;
			}
		}
		
//		trainingSet.close();
//		testSet.close();
		
		train1.close();
		test1.close();
		
		train2.close();
		test2.close();
		
		train3.close();
		test3.close();
		
		train4.close();
		test4.close();
		
		train5.close();
		test5.close();
	}

}
